package com.hl.vcd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hl.vcd.entity.PlayRecords;
import com.hl.vcd.entity.vo.PlayRecordsDetail;
import com.hl.vcd.mapper.PlayRecordsMapper;
import com.hl.vcd.service.PlayRecordsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 朱炫达
 */
@Service
@Transactional
public class PlayRecordsServiceImpl extends ServiceImpl<PlayRecordsMapper, PlayRecords> implements PlayRecordsService {
    @Override
    public void addPlayRecords(PlayRecords playRecords) {
        baseMapper.insert(playRecords);
    }

    @Override
    public void updatePlayRecords(PlayRecords playRecords) {
        baseMapper.updateById(playRecords);
    }

    @Override
    public void deletePlayRecordsById(String id) {
        baseMapper.deleteById(id);
    }

    @Override
    public void deleteAllPlayRecordsByUserId(String userId) {
        QueryWrapper<PlayRecords> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        baseMapper.delete(wrapper);
    }

    @Override
    public PlayRecords getPlayRecordsByUserIdAndVideoId(String userId, String videoId) {
        QueryWrapper<PlayRecords> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        wrapper.eq("video_id",videoId);
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public List<PlayRecordsDetail> getPlayRecordsDetailByUserId(String userId) {
        return baseMapper.getPlayRecordsDetailByUserId(userId);
    }

    @Override
    public List<PlayRecords> getPlayRecordsByUserId(String userId) {
        QueryWrapper<PlayRecords> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        return baseMapper.selectList(wrapper);
    }
}
